package com.study.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.study.model.Book;
import com.study.service.BookService;
import com.study.storage.BookDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @desc:
 * @author: panxiyi
 * @date: 2023/4/12 12:43 下午
 */

@Service
public class BookServiceImpl2 implements BookService {

    @Autowired
    private BookDao bookDao;

    @Override
    public Boolean save(Book book) {
        return bookDao.insert(book) > 0;
    }

    @Override
    public Boolean delete(Long id) {
        return bookDao.deleteById(id) > 0;
    }

    @Override
    public Boolean update(Book book) {
        return bookDao.updateById(book) > 0;
    }

    @Override
    public Book getById(Long id) {
        return bookDao.selectById(id);
    }

    @Override
    public List<Book> getALl() {
        return bookDao.selectList(null);
    }

    @Override
    public IPage<Book> getByPage(Integer currentPage, Integer pageSize) {
        IPage<Book> page = bookDao.selectPage(Page.of(currentPage, pageSize), null);
        return page;
    }
}
